<template>
	<view>
		<!-- 菜单 -->
		<!--#ifdef APP -->
		<u-sticky offset-top="0">
			<!--#endif-->
			<view class="top-warp">
				<u-tabs :list="tabs" @click="tabChange"
					itemStyle="width: 27%; height:80rpx; overflow:hidden;white-space: nowrap;text-overflow: ellipsis; -o-text-overflow:ellipsis;">
				</u-tabs>
			</view>
			<!--#ifdef APP -->
		</u-sticky>
		<!--#endif-->
		<!-- top="xxx"下拉布局往下偏移,防止被悬浮菜单遮住 -->
		<mescroll-body ref="mescrollRef" @init="mescrollInit" @up="upCallback" @down="downCallback">
			<!-- 数据列表 -->
			<Mypostlist :list="goods" :index="index" @userinfo="userinfo"></Mypostlist>
		</mescroll-body>
		<zero-back-top :scrollTop="scrollTop"></zero-back-top>
	</view>
</template>

<script>
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	import Mypostlist from "@/components/Mypostlist.vue"
	export default {
		mixins: [MescrollMixin], // 使用mixin (在main.js注册全局组件)
		components: {
			Mypostlist
		},
		data() {
			return {
				upOption: {
					page: {
						num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
					},
					noMoreSize: 4, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
					empty: {
						tip: '~ 搜索无数据 ~', // 提示
					}
				},
				goods: [], //列表数据
				tabs: [{
					name: 'Passed',
				}, {
					name: 'Under Processing',
				}, {
					name: 'Rejected',
				}, ],
				index: 0,
				scrollTop: 0,
			}
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop
		},
		onLoad() {
			this.locale()
			this.userinfo(0)
		},
		methods: {
			userinfo(index) {
				let params = {
					map: "applet_city_post_list",
					page: 0,
					type: 'myPost',
					status: 0
				}
				if (index == 1) {
					params.status = 1
				} else {
					params.status = 0
				}
				console.log(params)
				this.$Request({
					method: 'GET',
					data: params
				}).then(res => {
					if (res.data.ec == 200) {
						this.goods = res.data.data
						this.mescroll.endSuccess(res.data.data.length);
					} else {
						this.mescroll.endSuccess(0);
					}
				})
			},
			locale() {
				if (this._i18n.locale == 'zh') {
					this.tabs = [{
						name: '已通过',
					}, {
						name: '正在处理中',
					}, {
						name: '已拒绝',
					}]
				} else {
					this.tabs = [{
						name: 'Passed',
					}, {
						name: 'Under Processing',
					}, {
						name: 'Rejected',
					}, ]
				}
			},
			downCallback(page) {
				this.userinfo(this.index)
			},
			upCallback() {
				return
			},
			// 切换菜单
			tabChange(e) {
				console.log(e)
				this.index = e.index
				this.mescroll.resetUpScroll() // 再刷新列表数据
				this.goods = [] // 先置空列表,显示加载进度
				this.userinfo(e.index)
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f8f8f8;
	}

	.top-warp {
		width: 100%;
		background-color: #ffffff;

		.tip {
			font-size: 28upx;
			text-align: center;
		}
	}
</style>
